package com.eascs.afterloan.controller;

import java.text.DecimalFormat;
import java.text.Format;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.afterloan.entity.O2oLoanapplyOverdue;
import com.eascs.afterloan.form.O2oLoanapplyOverdueForm;
import com.eascs.afterloan.service.O2oLoanapplyOverdueService;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;
import com.eascs.workflow.common.entity.sys.ActOrgEntity;
import com.eascs.workflow.common.service.sys.SysOrgService;

@Controller
@RequestMapping("/o2oloanoverdue")
public class O2oLoanapplyOverdueController extends BaseMasterViewController {
	@Autowired
	O2oLoanapplyOverdueService service;
	@Reference
	SysOrgService sysOrgService;

	@RequestMapping("/index")
	public String index(O2oLoanapplyOverdueForm form) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "o2oloanoverdueFind");
		form.setPageSize(10);
		String pageUrl = "/o2oloanoverdue/index";
		List<ActOrgEntity> orgProvince = sysOrgService.getOrgProvince();
		ViewContext.put("ActOrgEntitys", orgProvince);
		String billCode = form.getBillCode() == null ? "" : form.getBillCode();
		String loanUserName = form.getLoanUserName() == null ? "" : form.getLoanUserName();
		String loanBankName = form.getLoanBankName() == null ? "" : form.getLoanBankName();
		String loanOperer = form.getLoanOperer() == null ? "" : form.getLoanOperer();
		String province = form.getProvince() == null ? "" : form.getProvince();
		String overdueTimeStart = form.getOverdueTimeStart() == null ? "" : form.getOverdueTimeStart();
		String overdueTimeEnd = form.getOverdueTimeEnd() == null ? "" : form.getOverdueTimeEnd();
		pageUrl = UrlUtil.appendUrl(pageUrl, "billCode", billCode);
		pageUrl = UrlUtil.appendUrl(pageUrl, "loanBankName", loanBankName);
		pageUrl = UrlUtil.appendUrl(pageUrl, "loanOperer", loanOperer);
		pageUrl = UrlUtil.appendUrl(pageUrl, "loanUserName", loanUserName);
		pageUrl = UrlUtil.appendUrl(pageUrl, "province", province);
		pageUrl = UrlUtil.appendUrl(pageUrl, "overdueTimeStart", overdueTimeStart);
		pageUrl = UrlUtil.appendUrl(pageUrl, "overdueTimeEnd", overdueTimeEnd);
		pageUrl = pageUrl + "&pageIndex=";
		PageResult<Object[]> pageResult = service.queryByPage(form);
		Button[] moreButtons = new Button[] { ButtonHelper.createRedirectButton("编辑", "/o2oloanoverdue/updateview?id=", "o2oloanoverdueUpdate"), ButtonHelper.createAjaxConfirmButton("删除", "/ro2oloanoverdue/delete?id=", "o2oloanoverdueDeelete") };
		String titles[] = { "贷款单号", "省区", "借款人姓名", "信贷经理", "放款银行", "逾期总额(元)", "逾期本金(元)", "逾期利息(元)", "罚息合计(元)", "逾期发生时间" };
		SelectDataOption[] selectDataOptions = { null, new SelectDataOption("REGIONALNAME_SB"), null, null, new SelectDataOption("BANKTYPEO2O"), null, null, null, null };
		PaginationInfo o2oPagingInfo = new PaginationInfo(pageResult, titles, pageUrl);
		o2oPagingInfo.setBuildPagingNavigation(true);
		o2oPagingInfo.setFirstRenderColumnIndex(1);
		o2oPagingInfo.setSelectDataOptions(selectDataOptions);
		o2oPagingInfo.setMoreButtons(moreButtons);
		o2oPagingInfo.setFormats(new Format[] { null, null, null, null, null, null, new DecimalFormat(",##0.00"), new DecimalFormat(",##0.00"), new DecimalFormat(",##0.00"), null });
		ViewContext.put("paginationInfo", o2oPagingInfo);
		ViewContext.put("vo", form);
		return "afterloan/overdue_index";
	}

	@RequestMapping("/addview")
	public String addView() {
		return "afterloan/overdue_add";
	}
	
	@RequestMapping("/updateview")
	public String updateView(String id) {
		O2oLoanapplyOverdue overdue = service.queryById(id);
		ViewContext.put("vo", overdue);
		return "afterloan/overdue_edit";
	}
}
